package com.lykj.modules.shop.controller;

import com.lykj.core.secure.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;

import javax.validation.Valid;

import com.lykj.core.mp.support.Condition;
import com.lykj.core.mp.support.Query;
import com.lykj.core.tool.api.R;
import com.lykj.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lykj.modules.shop.entity.UserFeedback;
import com.lykj.modules.shop.vo.UserFeedbackVO;
import com.lykj.modules.shop.wrapper.UserFeedbackWrapper;
import com.lykj.modules.shop.service.UserFeedbackService;
import com.lykj.core.boot.ctrl.LykjController;

/**
 * 问题反馈 控制器
 *
 * @author cxl
 * @since 2022-03-31
 */
@RestController
@AllArgsConstructor
@RequestMapping("lykj-shop/user/feedback")
@Api(value = "问题反馈", tags = "问题反馈接口")
public class UserFeedbackController extends LykjController {

	private final UserFeedbackService userFeedbackService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入userFeedback")
	public R<UserFeedbackVO> detail(UserFeedback userFeedback) {
		UserFeedback detail = userFeedbackService.getOne(Condition.getQueryWrapper(userFeedback));
		return R.data(UserFeedbackWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 问题反馈
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入userFeedback")
	public R<IPage<UserFeedbackVO>> list(UserFeedback userFeedback, Query query) {
		if (!Func.isNull(AuthUtil.getUserId())) {
			userFeedback.setUserId(AuthUtil.getUserId());
		}
		IPage<UserFeedback> pages = userFeedbackService.page(Condition.getPage(query), Condition.getQueryWrapper(userFeedback));
		return R.data(UserFeedbackWrapper.build().pageVO(pages));
	}

	/**
	 * 自定义分页 问题反馈
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入userFeedback")
	public R<IPage<UserFeedbackVO>> page(UserFeedbackVO userFeedback, Query query) {
		IPage<UserFeedbackVO> pages = userFeedbackService.selectUserFeedbackPage(Condition.getPage(query), userFeedback);
		return R.data(pages);
	}

	/**
	 * 新增 问题反馈
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入userFeedback")
	public R save(@Valid @RequestBody UserFeedback userFeedback) {
		userFeedback.setUserId(AuthUtil.getUserId());
		userFeedback.setStatus(0);
		return R.status(userFeedbackService.save(userFeedback));
	}

	/**
	 * 修改 问题反馈
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入userFeedback")
	public R update(@Valid @RequestBody UserFeedback userFeedback) {
		return R.status(userFeedbackService.updateById(userFeedback));
	}

	/**
	 * 新增或修改 问题反馈
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入userFeedback")
	public R submit(@Valid @RequestBody UserFeedback userFeedback) {
		if (!Func.isNull(userFeedback.getUserId()) && userFeedback.getUserId() != -1) {
			userFeedback.setUserId(AuthUtil.getUserId());
		}
		return R.status(userFeedbackService.saveOrUpdate(userFeedback));
	}

	/**
	 * 删除 问题反馈
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(userFeedbackService.deleteLogic(Func.toLongList(ids)));
	}

}
